﻿<controls:MetroWindow x:Class="Restaurant.Reservations.View.SettingsView"
                      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls"
                      xmlns:validationRules="clr-namespace:Restaurant.Reservations.ValidationRules"
                      Title="Settings"
                      Width="500"
                      Height="283"
                      BorderBrush="Black"
                      BorderThickness="1"
                      ResizeMode="NoResize"
                      ShowCloseButton="False"
                      ShowInTaskbar="False"
                      WindowStartupLocation="CenterOwner"
                      WindowStyle="ToolWindow">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <GroupBox Grid.Row="0"
                  Grid.Column="0"
                  Header="Tables">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="90" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" MinWidth="250" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Row="0"
                            Grid.Column="0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">
                    <TextBlock Text="Xml Filepath" />
                    <TextBlock Foreground="Red" Text="*" />
                </StackPanel>
                <TextBlock Grid.Row="0"
                           Grid.Column="1"
                           Margin="5"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Text=":" />
                <TextBox x:Name="TableXmlFilePathTextBox"
                         Grid.Row="0"
                         Grid.Column="2"
                         Margin="0,5,0,0"
                         HorizontalAlignment="Stretch"
                         VerticalAlignment="Center"
                         IsReadOnly="True">
                    <TextBox.Text>
                        <Binding Path="TableFilePath" UpdateSourceTrigger="Default">
                            <Binding.ValidationRules>
                                <validationRules:FileNotFoundValidationRule ValidatesOnTargetUpdated="True" />
                            </Binding.ValidationRules>
                        </Binding>

                    </TextBox.Text>
                </TextBox>
                <Button Grid.Row="0"
                        Grid.Column="3"
                        Margin="5,5,5,0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Command="{Binding BrowseTableXmlFilePath}"
                        Content="Browse" />
            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="1"
                  Grid.Column="0"
                  Header="Reservations">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="90" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" MinWidth="250" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Row="0"
                            Grid.Column="0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">
                    <TextBlock Text="File Name" />
                    <TextBlock Foreground="Red" Text="*" />
                </StackPanel>
                <TextBlock Grid.Row="0"
                           Grid.Column="1"
                           Margin="5"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Text=":" />
                <TextBox x:Name="XmlFileNameTextBox"
                         Grid.Row="0"
                         Grid.Column="2"
                         Margin="0,5,0,0"
                         HorizontalAlignment="Stretch"
                         VerticalAlignment="Center">
                    <TextBox.Text>
                        <Binding Path="ReservationFileName" UpdateSourceTrigger="PropertyChanged">
                            <Binding.ValidationRules>
                                <validationRules:NullOrEmptyValueValidationRule ValidatesOnTargetUpdated="True" />
                                <validationRules:RegexValidationRule ErrorMessage="XML file only." Pattern=".*\.xml?$" />
                            </Binding.ValidationRules>
                        </Binding>

                    </TextBox.Text>
                </TextBox>
                <StackPanel Grid.Row="1"
                            Grid.Column="0"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            Orientation="Horizontal">
                    <TextBlock Text="Output Location" />
                    <TextBlock Foreground="Red" Text="*" />
                </StackPanel>
                <TextBlock Grid.Row="1"
                           Grid.Column="1"
                           Margin="5"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Text=":" />
                <TextBox x:Name="ReservationDirecotryPathTextBox"
                         Grid.Row="1"
                         Grid.Column="2"
                         Margin="0,5,0,0"
                         HorizontalAlignment="Stretch"
                         VerticalAlignment="Center"
                         IsReadOnly="True">
                    <TextBox.Text>
                        <Binding Path="ReservationFileLocation" UpdateSourceTrigger="PropertyChanged">
                            <Binding.ValidationRules>
                                <validationRules:DirectoryNotFoundValidationRule ValidatesOnTargetUpdated="True" />
                            </Binding.ValidationRules>
                        </Binding>

                    </TextBox.Text>
                </TextBox>
                <Button Grid.Row="1"
                        Grid.Column="3"
                        Margin="5,5,5,0"
                        HorizontalAlignment="Right"
                        VerticalAlignment="Center"
                        Command="{Binding BrowseOutputFolder}"
                        Content="Browse" />
                <TextBlock Grid.Row="2"
                           Grid.Column="0"
                           HorizontalAlignment="Left"
                           VerticalAlignment="Center"
                           Text="Full Path" />
                <TextBlock Grid.Row="2"
                           Grid.Column="1"
                           Margin="5"
                           HorizontalAlignment="Center"
                           VerticalAlignment="Center"
                           Text=":" />
                <TextBlock x:Name="ReservationXmlFilePathTextBlock"
                           Grid.Row="2"
                           Grid.Column="2"
                           Grid.ColumnSpan="2"
                           Margin="0,5,0,0"
                           HorizontalAlignment="Stretch"
                           VerticalAlignment="Center">
                    <TextBlock.Text>
                        <Binding Path="ReservationFileFullpath" UpdateSourceTrigger="PropertyChanged">
                            <Binding.ValidationRules>
                                <validationRules:FileNotFoundValidationRule ValidatesOnTargetUpdated="True" />
                            </Binding.ValidationRules>
                        </Binding>

                    </TextBlock.Text>
                </TextBlock>
            </Grid>
        </GroupBox>
        <StackPanel Grid.Row="2"
                    HorizontalAlignment="Right"
                    VerticalAlignment="Center"
                    Orientation="Horizontal">
            <Button Margin="5"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Command="{Binding RevalidateCommand}"
                    Content="Revalidate">
                <Button.ToolTip>
                    <ToolTip Content="Press to re-validate all file and directory paths." Style="{StaticResource GenericToolTipStyle}" />
                </Button.ToolTip>
            </Button>
            <Button Margin="5"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Command="{Binding SaveSettingsCommand}"
                    Content="Save">
                <Button.Style>
                    <Style TargetType="Button">
                        <Setter Property="IsEnabled" Value="False" />
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding Path=(Validation.HasError), ElementName=TableXmlFilePathTextBox}" Value="False" />
                                    <Condition Binding="{Binding Path=(Validation.HasError), ElementName=ReservationDirecotryPathTextBox}" Value="False" />
                                    <Condition Binding="{Binding Path=(Validation.HasError), ElementName=ReservationXmlFilePathTextBlock}" Value="False" />
                                    <Condition Binding="{Binding Path=(Validation.HasError), ElementName=XmlFileNameTextBox}" Value="False" />
                                </MultiDataTrigger.Conditions>
                                <Setter Property="IsEnabled" Value="True" />
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </Button.Style>
            </Button>
        </StackPanel>
    </Grid>
</controls:MetroWindow>